<?php

/*

Upgrading Gallery (upgrade_gallery.pro.php)

*/
ob_start();
include "global.inc.php";

$find_gallery = fetch("SELECT * FROM usergallerys WHERE owner = '$userid' AND game = '$game'");

if (!$find_gallery[id])
{
	die("You do not have a gallery yet, please click <a href=makegallery.php?game=$game>here</a> to create one.$closeHTML");
}

$max_stock = $find_gallery[gallery_size] * 5;
$cost_2_upgrade = ($find_gallery[gallery_size] * 10) + 10;
$next_level = $find_gallery[gallery_size] + 1;

if ($use_token == "true")
{
	$findTokens = fetch("SELECT * FROM upgrade_tokens WHERE user = '$userid' AND game = '$game' AND upgrade = 'gallery'");
	if ($findTokens[ammount] <= 0)
	{
		die(header(error("upgrade_gallery.php?game=$game","You do not have any Upgrade Gallery Tokens!")));
	}

	mysql_query("UPDATE upgrade_tokens SET ammount=$findTokens[ammount]-1 WHERE user = '$userid' AND game = '$game' AND upgrade = 'gallery'");

	mysql_query("UPDATE usergallerys SET gallery_size=$find_gallery[gallery_size]+1 WHERE owner = '$userid' AND game = '$game'");

	die(header(error("upgrade_gallery.php?game=$game","You used a token and your gallery has been upgraded!")));
}

if ($use_token != "true")
{

	if ($next_upgrade != $next_level)
	{
		die(header(error("upgrade_gallery.php?game=$game","An error occured while processing 	this page, please be sure to only click the upgrade button once!")));
	}

	if ($points < $cost_2_upgrade)
	{
		die(header(error("upgrade_gallery.php?game=$game","You cannot afford to upgrade your 	gallery right now.")));
	}

	mysql_query("UPDATE usergallerys SET gallery_size=$find_gallery[gallery_size]+1 WHERE 	owner = '$userid' AND game = '$game'");

	points($game,"$username", "-$cost_2_upgrade");
}

die(header(error("upgrade_gallery.php?game=$game","Your gallery has been upgraded!")));

?>